<?php
session_start();
if(isset($_POST["logout"]))
{
	session_destroy();
	header ("Refresh: 0; URL=login.php");
	die();
}
if(!isset($_SESSION['logged_voting']))
{
	header ("Refresh: 0; URL=login.php");
	die();
}
require "config.php";
require "language.php";
?>
<table width='100%' border='0'>
<tr>
		<td align='left'><?php require "language_form.php"; ?></td>
		<td align='right'>
			<form method="POST">
				<input type="submit" name="logout" value="<?php echo $language['logout'] ?>">
			</form>
		</td>
	</tr>
</table>
<?php
require "title.php";
require "functions.php";
require "tabs.php";
$id = $_SESSION['user_id'];
$acc_name = $_SESSION['user_name'];
if(isset($_POST["reward"]))
	chose_reward($id,$_SESSION['char_name'],$_POST["reward"],$realm_DB,$user,$pass,$server_ip,$remote_port);
create_vote_lists($id,$realm_DB);
$points = show_points($id,$realm_DB);
echo "<center>".$language['cur_acc'].": ".$acc_name."</center>";
echo "<center>".$language['points_1'].": ".$points."</center>";
$passed_time = show_passed_time($realm_DB);
if($passed_time=='0')
	echo "<center>".$language['not_voted_yet']."</center>";
else
	echo "<center>".$language['last_vote'].": ".$passed_time."</center>";
if(isset($_POST["site"]))
	vote(intval($_POST["site"]),$id,$realm_DB);
echo "<br>";
if(!(return_voted_sites($realm_DB) == count_tab_sites()))
{
	if(check_date_points($id,$realm_DB))
	{
?>
<form action='index.php' method='post'>
<table border='1' cellspacing='1' cellpadding='3' align='center'>
	<tr>
		<th colspan='2'><?php echo $language['chose_site'] ?></th>
	</tr>
	<tr>
		<td><?php echo $language['voting_sites'] ?></td>
		<td>
			<select name='site' onchange="this.form.submit();">
				<option value='0'></option>
				<?php
				show_sites_menu($realm_DB);
				?>
			</select>
		</td>
	</tr>
</table>
</form> 
<?php
	}
	else 
		echo "<center>".$language['vote_limit_reached']."<br>".$language['vote_tomorrow']."</center>";
}
else
	echo "<center>".$language['vote_after'].": ".show_time_to_vote($realm_DB)."</center>";
if ($points == 0)
	echo "<center>".$language['cant_reward']."</center>";
else 
{
?>
<form action='index.php' method='post'>
<table border='1' cellspacing='1' cellpadding='3' align='center'>
	<tr>
		<th colspan='2'><?php echo $language['choose_char_for_reward'] ?></th>
	</tr>
	<tr>
		<td><?php echo $language['available_chars'] ?></td>
		<td>
			<select name='character' onchange="this.form.submit();">
				<option value='0'></option>
				<?php
				show_chars_menu($id,$chars_DB);
				?>
			</select>
		</td>
	</tr>
</table>
</form> 	
<?php
	if(isset($_POST["character"]))
		add_char_to_session(intval($_POST["character"]),$chars_DB);
	if(isset($_SESSION['char_name']))
	{
		echo "<center>".$language['cur_char'].": ".$_SESSION['char_name']."</center><br>";
		show_rewards($id,$realm_DB);
	}
}
?>